package com.atgg.condition;

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.context.annotation.Conditional;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;


public class WindowsCondition implements Condition {

    /**
     *
     * @param conditionContext   : 判断条件使用的上下文的环境
     * @param annotatedTypeMetadata：注释信息
     * @return
     */
    @Override
    public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
        // 获取到ioc使用的beanFactory
        ConfigurableListableBeanFactory beanFactory = conditionContext.getBeanFactory();
       //  获取类加载器
        ClassLoader classLoader = conditionContext.getClassLoader();
        System.out.println(classLoader);
        // 获取运行的环境
        Environment environment = conditionContext.getEnvironment();
        String property = environment.getProperty("os.name");
        if (property.toLowerCase().contains("windows")){
            return true;
        }
        // 获取bean定义的信息
        BeanDefinitionRegistry registry = conditionContext.getRegistry();
        return false;
    }


}
